package com.design.domain.result;

import com.design.util.CodeUtil;
import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class CommonResult<T> {


	private Integer code;

	private String message;

	private String msg;

	private T data;

	private Integer count;

	private CommonResult(Integer code, String message, String msg) {
		this.code = code;
		this.message = message;
		this.msg = msg;
	}

	public CommonResult(Integer code, String message, String msg, T data) {
		this.code = code;
		this.message = message;
		this.data = data;
		this.msg = msg;
	}

	public CommonResult(Integer code, String message, String msg, T data, Integer count) {
		this.code = code;
		this.message = message;
		this.data = data;
		this.count = count;
		this.msg = msg;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public static <T> CommonResult error(String message) {
		return new CommonResult(CodeUtil.ERROR_CODE_1, message, message, null);
	}

	public static <T> CommonResult error(int code,String message) {
		return new CommonResult(code, message, message, null);
	}

	public static <T> CommonResult fsuccess(String message) {
		return new CommonResult(CodeUtil.SUCCESS_CODE_1, message, message, null);
	}

	public static <T> CommonResult error(String message, T data) {
		return new CommonResult(CodeUtil.ERROR_CODE_1, message, message, data);
	}

	public static <T> CommonResult error(Integer code, String message) {
		return new CommonResult(code, message, message);
	}

	public static CommonResult success() {
		return new CommonResult(CodeUtil.SUCCESS_CODE_1, "success", "success");
	}

	public static CommonResult sendSuccseeMessage(String message) {
		return new CommonResult(CodeUtil.SUCCESS_CODE_1, message, message);
	}

	public static <T> CommonResult success(T data) {
		return new CommonResult(CodeUtil.SUCCESS_CODE_1, "success", "success", data);
	}

	public static <T> CommonResult success(T data, int count) {
		return new CommonResult(CodeUtil.SUCCESS_CODE_1, "success", "success", data, count);
	}

	public static <T> CommonResult success(T data, int count, String message) {
		return new CommonResult(CodeUtil.SUCCESS_CODE_1, message, message, data, count);
	}

	@Override
	public String toString() {
		return "CommonResult{" +
				"code=" + code +
				", message='" + message + '\'' +
				", data=" + data +
				", count=" + count +
				'}';
	}
}
